
<?php

$this->breadcrumbs = array(
    Drill::label(2),
    Yii::t('app', 'List'),
);

$this->menu = array(
    array('label'=>'Search', 'url'=>array("drill/search"),
        'linkOptions'=> array('class' => 'icon icon-search3 tb-gray'),
    ),
);
?>

<h2 class="form-header">
    <?php
        echo CHtml::encode($this->pageTitle);

        echo "<div class=\"page-size\"><a onclick=\"cat_filter.mode.value='grid';cat_filter.submit();\" class=\"icon icon-grid3 title-link-white\"></a></div>";
        echo "<div class=\"page-size\"><a onclick=\"cat_filter.mode.value='list';cat_filter.submit();\"  class=\"icon icon-list2 title-link-white\"></a></div>";

    ?>
</h2>


<?php
    $mode = "unkonwn";
    if(isset($_SESSION["drill-library-mode"])) { $mode = $_SESSION["drill-library-mode"]; }
?>

<div class="list-filter">
    <form name="cat_filter" method="GET" action="index.php">
    <input type="hidden" name="r" value="drill/list">
    <input type="hidden" name="mode" value="<?php echo $mode ?>">
    <label>Name : </label>
    <?php
    if(isset($_REQUEST["search"])) { $search = $_REQUEST["search"]; }
    else { $search = ""; }
    ?>
    <input class="input-medium" type="search" name="search" value="<?php echo $search; ?>" onsearch="cat_filter.submit();">
    &nbsp;&nbsp;&nbsp;&nbsp;
    <label>Category : </label>
    <?php
        $filter_data = Array(""=>"");
        $filter_data = array_merge($filter_data,GxHtml::listDataEx(DrillCategory::model()->findAll(),'id','id','drill_section_id'));
        $selected = "";
        if(isset($_REQUEST["category"])) { $selected = $_REQUEST["category"]; }
        echo Chosen::dropDownList("category", $selected, $filter_data, array('placeholder'=>'Select a Category','class'=>'input-medium','onChange'=>'cat_filter.submit();'));
    ?>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <label>Tag : </label>
    <?php
        $filter_data = Array(""=>"");
        $filter_data = array_merge($filter_data,GxHtml::listDataEx(Tag::model()->findAllAttributes(null, true)));
        $selected = "";
        if(isset($_REQUEST["tag"])) { $selected = $_REQUEST["tag"]; }
        echo Chosen::dropDownList('tag', $selected, $filter_data,array('class'=>'input-medium','onChange'=>'cat_filter.submit();'));
    ?>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <label>Players : </label>
    <?php
        $filter_data = Drill::model()->GetPlayerNumberArray();
        if(isset($_REQUEST["players"])) { $selected = $_REQUEST["players"]; }
        echo Chosen::dropDownList('players', $selected, $filter_data,array('class'=>'input-xxsmall','onChange'=>'cat_filter.submit();'));
    ?>

    </form>
</div>


<?php

if($mode=="list") {
    $this->widget('zii.widgets.CListView', array(
        'id' => 'drill-list',
        'dataProvider' => $dataProvider,
        'pager' => Array(
            'firstPageLabel' => '<<',
            'prevPageLabel' => '<',
            'nextPageLabel' => '>',
            'lastPageLabel' => '>>',
        ),
        'enableSorting' => true,
        'itemView' => '_item',
        'sortableAttributes' => array(
            'name',
            'category',
            'players'
        ),
        'template' => "{sorter}{summary}{items}\n{pager}",
    ));
} // Mode == full

else if($mode=="grid") {
    $this->widget('zii.widgets.CListView', array(
        'id' => 'drill-grid',
        'dataProvider' => $dataProvider,
        'pager' => Array(
            'firstPageLabel' => '<<',
            'prevPageLabel' => '<',
            'nextPageLabel' => '>',
            'lastPageLabel' => '>>',
        ),
        'enableSorting' => true,
        'itemView' => '_grid',
        'sortableAttributes' => array(
            'name',
            'category',
            'players'
        ),
        'template' => "{sorter}{summary}{items}\n{pager}",
    ));
}
